Ubuntu 终端使用shadowsocks全局代理
配置 ShadowSocks 客户端
1 | sudo apt-get install python-pip |
配置文件如下:
1 | { |
配置说明:
- “server”
- 服务端ip
- “method”
- 加密方式
- “password”
- 服务端密码
- “fast_open”
- 可选 true 或 false。如果你的服务器 Linux 内核在3.7+,可以开启 fast_open 以降低延迟。开启方法: echo 3 > /proc/sys/net/ipv4/tcp_fastopen 开启之后,将 fast_open 的配置设置为 true 即可
开启shadowsocks:
1 | tmux |
如果启动sslocal
出现错误:1
AttributeError: /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: undefined symbol: EVP_CIPHER_CTX_cleanup
参考解决方法: run sslocal raise error:
1 | pip install -U git+https://github.com/shadowsocks/shadowsocks.git@master |
使用 privoxy 将Sock5代理转化为Http代理
1 | sudo apt-get install privoxy -y |
修改配置文件:
1 | sudo cp /etc/privoxy/config /etc/privoxy/config.bak # 备份配置文件 |
找到 listen-address
确保有这行代码 listen-address 127.0.0.1:8118
找到 forward-socks5
确保有这行代码(没有自己加) forward-socks5 / 127.0.0.1:1080 .
配置文件如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26user-manual /usr/share/doc/privoxy/user-manual
confdir /etc/privoxy
logdir /var/log/privoxy
actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on.
actionsfile default.action # Main actions file
actionsfile user.action # User customizations
filterfile default.filter
filterfile user.filter # User customizations
logfile logfile
listen-address 127.0.0.1:8118
listen-address [::1]:8118
toggle 1
enable-remote-toggle 0
enable-remote-http-toggle 0
enable-edit-actions 0
enforce-blocks 0
buffer-limit 4096
enable-proxy-authentication-forwarding 0
forwarded-connect-retries 0
accept-intercepted-requests 0
allow-cgi-request-crunching 0
split-large-forms 0
keep-alive-timeout 5
tolerate-pipelining 1
socket-timeout 300
forward-socks5 / 127.0.0.1:1080 .
启动privoxy
1 | sudo service privoxy start |
配置转发
1 | export http_proxy="http://127.0.0.1:8118" |
测试
1 | root@kali:~# curl 4.icanhazip.com |
也可以使用 Polipo 代替 Privoxy
1 | sudo apt-get install polipo -y |
服务器重启后,下面两句需要重新执行:
1 | sudo sslocal -c /etc/ssclient.conf -d start |
取消代理:
1 | unset http_proxy |
参考链接:
- Ubuntu 使用 ShadowSocks + Privoxy 代理
- 五大开源 Web 代理服务器横评:Squid、Privoxy、Varnish、Polipo、Tinyproxy
- Ubuntu server命令行配置shadowsocks全局代理
- 使用Privoxy、Polipo、3proxy转化Sock5代理为Http代理
使用supervisor
管理shadowsocks
进程
安装supervisor1
sudo apt-get install supervisor
添加ss配置文件
vim /etc/supervisor/conf.d/ss.conf1
2
3
4
5
6
7
8[program:ss]
command=/usr/local/bin/sslocal -c /etc/ssclient.conf
user=root
directory=/root
stdout_logfile=/var/log/supervisor/%(program_name)s-stdout.log
stderr_logfile=/var/log/supervisor/%(program_name)s-stderr.log
killasgroup=true
stopasgroup=true
使用supervisor
启动ss:1
2
3
4
5
6
7sudo service supervisor restart
sudo supervisorctl restart ss
root@huang:~# lsof -i :1080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sslocal 3148 root 3u IPv4 33691 0t0 TCP localhost:socks (LISTEN)
sslocal 3148 root 4u IPv4 33692 0t0 UDP localhost:socks
为git协议设置代理
使用ProxyChains-NG
1 | git clone https://github.com/rofl0r/proxychains-ng.git |
sudo vim /etc/proxychains.conf
添加如下配置:1
2
3
4
5
6
7
8
9
10strict_chain
proxy_dns
remote_dns_subnet 224
tcp_read_time_out 15000
tcp_connect_time_out 8000
localnet 127.0.0.0/255.0.0.0
quiet_mode
[ProxyList]
socks5 127.0.0.1 1080
在需要代理的命令前加上 proxychains4
,如:1
2
3proxychains4 curl ip.sb
proxychains4 git clone git://github.com/WordPress/WordPress.git
使用tsocks
1 | apt-get install tsocks |
配置如下:1
2
3
4
5
6
7
8
9
10
11
12
13local = 192.168.0.0/255.255.255.0
local = 10.0.0.0/255.0.0.0
path {
reaches = 150.0.0.0/255.255.0.0
reaches = 150.1.0.0:80/255.255.0.0
server = 10.1.7.25
server_type = 5
default_user = delius
default_pass = hello
}
server = 127.0.0.1
server_type = 5
server_port = 1080
使用:1
tsocks curl ip.sb